/**
 * react-loadable的封装
 */

import React from 'react';
import Loadable from 'react-loadable';
import Loading from './loading';
import ComponentWithReducers from './reducers';

export default (opts) => {
  return Loadable(
    Object.assign(
      {
        loading: Loading,
        delay: 500,
        render(loaded, props) {
          const Component = loaded.default;
          if (Component.reducers) {
            return (
              <ComponentWithReducers
                reducers={Component.reducers}
                component={Component}
                props={props}
              />
            );
          } else {
            return <Component {...props} />;
          }
        },
      },
      opts,
    ),
  );
};
